/**
 * @Description: 万智牌管理功能
 * @author XuYang.Geng
 * @date 2021/12/22
 */

import { ErrorMessageMode } from '/#/axios';
import { defHttp } from '/@/utils/http';
import { isArray } from '/@/utils/is';
import type { CardListQuery, CardList, CardDetail } from './model/cardModel';

enum Api {
  CardList = '/tool/gateruler/card-list',
  CardDetail = '/tool/gateruler/card-info',
}

// 获取卡牌列表
export function CardListApi(params: CardListQuery, model: ErrorMessageMode = 'dialog') {
  const jsonParams: any = {};
  for (const item in params) {
    if (isArray(params[item])) {
      jsonParams[item] = params[item].length ? params[item].join(',') : undefined;
      continue;
    }
    jsonParams[item] = params[item];
  }
  return defHttp.post<CardList>(
    {
      url: Api.CardList,
      data: jsonParams,
    },
    {
      errorMessageMode: model,
    }
  );
}

// 获取卡牌详情
export function CardDetailApi(params: Pick<CardDetail, 'card_id'>, model: ErrorMessageMode = 'dialog') {
  return defHttp.post<CardDetail>(
    {
      url: Api.CardDetail,
      data: params,
    },
    {
      errorMessageMode: model,
    }
  );
}
